﻿@page "/datagrid-pager-api"

@using RadzenBlazorDemos.Data
@using RadzenBlazorDemos.Models.Northwind
@using Microsoft.EntityFrameworkCore

@inject NorthwindContext dbContext

<h1>DataGrid <strong>Pager API</strong></h1>

<RadzenExample Name="DataGridPagerApi" Heading="false">
    <div style="margin-bottom: 16px">
        <RadzenButton Click="@FirstPage" Text="First page" />
        <RadzenButton Click="@TenthPage" Text="10th page" />
        <RadzenButton Click="@LastPage" Text="Last page" />
    </div>
   <RadzenDataGrid @ref=@dataGrid Data="@orderDetails" TItem="OrderDetail" AllowPaging="true" AllowSorting="true" PageSizeOptions="@pageSizeOptions">
        <Columns>
            <RadzenDataGridColumn TItem="OrderDetail" Property="OrderID" Title="OrderID" />
            <RadzenDataGridColumn TItem="OrderDetail" Property="ProductID" Title="ProductID" />
            <RadzenDataGridColumn TItem="OrderDetail" Property="UnitPrice" Title="Unit Price">
                <Template Context="detail">
                    @String.Format(new System.Globalization.CultureInfo("en-US"), "{0:C}", detail.UnitPrice)
                </Template>
            </RadzenDataGridColumn>
            <RadzenDataGridColumn TItem="OrderDetail" Property="Quantity" Title="Quantity" />
            <RadzenDataGridColumn TItem="OrderDetail" Property="Discount" Title="Discount">
                <Template Context="detail">
                    @String.Format("{0}%", detail.Discount * 100)
                </Template>
            </RadzenDataGridColumn>
        </Columns>
    </RadzenDataGrid>
</RadzenExample>

@code {
    RadzenDataGrid<OrderDetail> dataGrid;
    IEnumerable<int> pageSizeOptions = new int[] { 10, 20, 30 };
    IEnumerable<OrderDetail> orderDetails;

    async Task FirstPage()
    {
        await dataGrid.FirstPage();
    }
    async Task TenthPage()
    {
        await dataGrid.GoToPage(9);
    }
    async Task LastPage()
    {
        await dataGrid.LastPage();
    }

    protected override void OnInitialized()
    {
        orderDetails = dbContext.OrderDetails;
    }
}